// Jose J. Alcocer 
// 
//
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* SET UP WORKSPACE 
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

* clear existing work
clear all

* set working directory
cd "/Users/josealcocer/Library/CloudStorage/Dropbox/All School Files/USC PHD/Files/Non-Class Material/Research/1_Impact of Minority Legislators on Non Roll Call Activity/Main Files/data"

* create frame and import data
frame create minority
frame change minority
import delimited "minority.csv"

* repeat process above for new frames
frame create nonminority
frame change nonminority
import delimited "placebo_non_minority.csv"

frame create placebo_minority
frame change placebo_minority
import delimited "placebo_minority.csv"



*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* FIRST ANALYSIS - MINORITY LEGISLATORS REPLACING WHITE LEGISLATORS (TREATMENT)
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

*-----------------*
* Bill Sponsorship
*-----------------*

frame change minority


preserve

drop if state_district_code == "CA24"
drop if state_district_code == "DE1"
drop if state_district_code == "CO2"
drop if state_district_code == "CT5"
drop if state_district_code == "MA7"
drop if state_district_code == "NY14"
drop if state_district_code == "TX16"
drop if state_district_code == "TX29"
drop if state_district_code == "WA7"
drop if state_district_code == "FL7"
drop if state_district_code == "FL10"
drop if state_district_code == "VA4"
drop if state_district_code == "CA21"
drop if state_district_code == "CA39"
drop if state_district_code == "IL14"
drop if state_district_code == "TX32"
drop if state_district_code == "KS3"
drop if state_district_code == "NM2"


sum
/*
    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        name |          0
       party |          0
billsspons~d |        288    21.84375    13.34975          0         74
billscospo~d |        288      407.75    194.2762          0       1235
    congress |        288       114.5     1.11998        113        116
-------------+---------------------------------------------------------
          id |          0
state_dist~e |          0
    democrat |        288           1           0          1          1
      female |        288    .3055556    .4614441          0          1
       black |        288           0           0          0          0
-------------+---------------------------------------------------------
      latine |        288           0           0          0          0
       asian |        288           0           0          0          0
     treated |        288           0           0          0          0
*/

restore

*----------------*
* Bootstrapped SE 
*----------------*

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  -8.54352    3.05152    -2.80    0.005   -14.52440    -2.56265
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

*----------------*
* Bootstrapped SE 
*----------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Cosponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  73.53088   32.16809     2.29    0.022    10.48258   136.57918
-----------------------------------------------------------------------------
*/



*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* SECOND ANALYSIS - MINORITY LEGISLATORS REPLACING WHITE LEGISLATORS (TREATMENT)
*                   CONTROLLING FOR PARTY CHANGE 
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

*-----------------*
* Bill Sponsorship
*-----------------*

drop if state_district_code == "VA4"
drop if state_district_code == "CA21"
drop if state_district_code == "CA39"
drop if state_district_code == "TX32"
drop if state_district_code == "FL7"
drop if state_district_code == "FL10"
drop if state_district_code == "IL14"
drop if state_district_code == "KS3"
drop if state_district_code == "NM2"


sum 

/*

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        name |          0
       party |          0
billsspons~d |        324     22.0463    12.94598          0         74
billscospo~d |        324    407.6852    191.3907          0       1235
    congress |        324       114.5    1.119763        113        116
-------------+---------------------------------------------------------
          id |          0
state_dist~e |          0
    democrat |        324           1           0          1          1
      female |        324    .3148148    .4651605          0          1
       black |        324    .0154321    .1234544          0          1
-------------+---------------------------------------------------------
      latine |        324    .0154321    .1234544          0          1
       asian |        324    .0061728    .0784457          0          1
     treated |        324     .037037    .1891447          0          1
*/


*----------------*
* Bootstrapped SE 
*----------------*

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated | -10.93567    3.50815    -3.12    0.002   -17.81151    -4.05983
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

*----------------*
* Bootstrapped SE 
*----------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Cosponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  91.22147   28.58560     3.19    0.001    35.19472   147.24822
-----------------------------------------------------------------------------
*/



*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* THIRD ANALYSIS - EXPLORING GENDERED EFFECTS OF MINORITY LEGISLATORS
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

** Men

preserve

drop if state_district_code == "DE1"
drop if state_district_code == "CT5"
drop if state_district_code == "MA7"
drop if state_district_code == "NY14"
drop if state_district_code == "TX16"
drop if state_district_code == "TX29"
drop if state_district_code == "WA7"


summarize

/*
    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        name |          0
       party |          0
billsspons~d |        296    22.06081    13.34762          0         74
billscospo~d |        296    408.7331    193.1953          0       1235
    congress |        296       114.5    1.119927        113        116
-------------+---------------------------------------------------------
          id |          0
state_dist~e |          0
    democrat |        296           1           0          1          1
      female |        296    .3040541    .4607846          0          1
       black |        296    .0033784    .0581238          0          1
-------------+---------------------------------------------------------
      latine |        296    .0067568    .0820601          0          1
       asian |        296           0           0          0          0
     treated |        296    .0101351    .1003316          0          1
*/

*-----------------*
* Bill Sponsorship
*-----------------*

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr


// Results of Weigted SDID
/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  -4.08097   10.64553    -0.38    0.701   -24.94582    16.78389
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  77.69227   14.20868     5.47    0.000    49.84377   105.54077
-----------------------------------------------------------------------------
*/

restore


** Women

preserve

drop if state_district_code == "CA24"
drop if state_district_code == "CO2"

summarize
/*

    Variable |        Obs        Mean    Std. dev.       Min        Max
-------------+---------------------------------------------------------
        name |          0
       party |          0
billsspons~d |        316     21.8481    12.93754          0         74
billscospo~d |        316    406.7627    192.3342          0       1235
    congress |        316       114.5    1.119807        113        116
-------------+---------------------------------------------------------
          id |          0
state_dist~e |          0
    democrat |        316           1           0          1          1
      female |        316    .3164557    .4658306          0          1
       black |        316    .0126582    .1119718          0          1
-------------+---------------------------------------------------------
      latine |        316    .0094937    .0971257          0          1
       asian |        316    .0063291    .0794293          0          1
     treated |        316     .028481    .1666064          0          1
*/

*-----------------*
* Bill Sponsorship
*-----------------*

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results of Weigted SDID
/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated | -13.26414    3.49736    -3.79    0.000   -20.11883    -6.40945
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  94.96640   37.40110     2.54    0.011    21.66159   168.27121
-----------------------------------------------------------------------------
*/

restore



*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* FOURTH ANALYSIS - ROBUSTNESS CHECK; PRIMARY OUTCOME EFFECTS
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

** Open Seat Primary

preserve
drop if state_district_code == "NY14"
drop if state_district_code == "MA7"

*-----------------*
* Bill Sponsorship
*-----------------*

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results of Weigted SDID
/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  -9.70247    3.78914    -2.56    0.010   -17.12906    -2.27589
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  94.38414   34.16938     2.76    0.006    27.41339   161.35489
-----------------------------------------------------------------------------
*/

restore


** Outprimarying Incumbent

preserve 

drop if state_district_code == "CA24"
drop if state_district_code == "CO2"
drop if state_district_code == "CT5"
drop if state_district_code == "TX16"
drop if state_district_code == "TX29"
drop if state_district_code == "DE1"
drop if state_district_code == "WA7"

*-----------------*
* Bill Sponsorship
*-----------------*

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results of Weigted SDID
/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated | -18.13226    9.09412    -1.99    0.046   -35.95642    -0.30810
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  72.71841   20.31391     3.58    0.000    32.90388   112.53294
-----------------------------------------------------------------------------
*/

restore



*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* FIFTH ANALYSIS - WHITE LEGISLATORS REPLACING WHITE LEGISLATORS (PLACEBO A)
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

*-----------------*
* Bill Sponsorship
*-----------------*

frame change nonminority

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results of Weigted SDID
/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated | -15.95389   11.38700    -1.40    0.161   -38.27200     6.36422
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |  57.07918  104.59980     0.55    0.585   -1.48e+02   262.09102
-----------------------------------------------------------------------------
*/


*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*
* SIXTH ANALYSIS - MINORITY LEGISLATORS REPLACING MINORITY ONES (PLACEBO B)
*------------------------------------------------------------------------------*
*------------------------------------------------------------------------------*

*-----------------*
* Bill Sponsorship
*-----------------*

frame change placebo_minority

#delimit ;
sdid billssponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results of Weigted SDID
/*
-----------------------------------------------------------------------------
billsspons~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated |   1.68338    5.38859     0.31    0.755    -8.87806    12.24483
-----------------------------------------------------------------------------
*/


*------------------*
* Bill Cosponsorship
*------------------*

#delimit ;
sdid billscosponsored state_district_code congress treated,
	vce(bootstrap) reps(1000) seed(444)
	graph g1on g1_opt(xtitle("Congressional District")) 
	g2_opt(ytitle("No. of Bills Sponsored") 
	xtitle("Congressional Session"));
#delimit cr

// Results for weighted regression
/*
-----------------------------------------------------------------------------
billscospo~d |     ATT     Std. Err.     t      P>|t|    [95% Conf. Interval]
-------------+---------------------------------------------------------------
     treated | -1.05e+02   52.14549    -2.02    0.044   -2.07e+02    -2.88722
-----------------------------------------------------------------------------

*/


